/* 
 * @description: 构建SliverAppBar
 * @author: Jane 
 * @date: 2023-10-11 16:56:41
 */
import 'package:basic_common/common_exports.dart';

class BuildSliverAppBar extends StatelessWidget {
  BuildSliverAppBar(
      {super.key,
      required this.expendHeight,
      required this.height,
      required this.cover,
      required this.coverHeight,
      required this.radius,
      required this.bgChild,
      required this.child,
      required this.bgColor,
      required this.title});

  final double height;
  final double expendHeight;
  final String cover;
  final double coverHeight;
  final double radius;
  final Widget child;
  final Widget bgChild;
  final Widget title;
  final Color bgColor;

  // final double _statusBarHeight = MediaQueryData.fromWindow(window).padding.top;
  // final _screenWidth = MediaQueryData.fromWindow(window).size.width;

  @override
  Widget build(BuildContext context) {
    return SliverAppBar(
      backgroundColor: bgColor ?? Colors.blue,
      iconTheme: const IconThemeData(color: Colors.white),
      pinned: true,
      expandedHeight: height - ScreenHelper.topSafeHeight + expendHeight,
      flexibleSpace: FlexibleSpaceBar(
        centerTitle: true,
        title: title,
        collapseMode: CollapseMode.parallax,
        background: Stack(
          children: [
            SizedBox(
              height: coverHeight + expendHeight,
              width: ScreenHelper.screenWidth,
              // TODO:更改以下代码
              child: bgChild,
            ),
            Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: ScreenHelper.screenWidth,
                margin: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
                height: height - coverHeight + radius,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.vertical(
                    top: Radius.circular(radius),
                  ),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black.withOpacity(.1),
                      offset: const Offset(0, -2),
                      blurRadius: 4,
                    ),
                  ],
                ),
                child: child,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
